/*
 * Created by: Jonathan Messer
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace time
{
    public partial class notepad : Form
    {
        string filePath = (Application.StartupPath + @"\notepad.jon"); // sets the file path to the notepad file, with an unique extension ^_^

        public notepad(int position) // gets the position from the calling method
        {
            InitializeComponent();
            DesktopLocation = new System.Drawing.Point(position, 22); // starts the postion, based on the program location
            this.StartPosition = FormStartPosition.Manual; 
            if (File.Exists(filePath)) // check if the file exists
            {
                StreamReader sr = new StreamReader(filePath); // new instance of the stream reader
                string savedText = sr.ReadToEnd(); // reads all contents of the saved text, and then saves it as a variable
                txtNotepad.Text = savedText; // puts the saved text in the text box
                sr.Close(); // closes the stream writer
            }
            else // if no save file is found
                txtNotepad.Text = ""; // set the text of the notepad to blank
        }

        private void btnExit_Click(object sender, EventArgs e) // the exit button
        {
            this.Close(); // closes the notepad
        }

        private void btnSave_Click(object sender, EventArgs e) // saves the notepad info
        {
            StreamWriter sw = new StreamWriter(filePath); // new instance of the stream writer
            sw.WriteLine(txtNotepad.Text); // saves whatever is typed in the notepad into the file
            sw.Close(); // closes the stream writer
        }

        private void notepad_Load(object sender, EventArgs e)
        {

        }
    }
}